import 'dart:ui' as prefix0;
import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_simple_video_player/flutter_simple_video_player.dart';

import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:study/list/YingZhiYingHui.dart';
import 'package:study/list/listdata.dart';
import 'package:study/list/question.dart';
import 'package:study/page/chapterone.dart';

class CategoryPage extends StatefulWidget {
  @override
  _CategoryPageState createState() => _CategoryPageState();
}

class _CategoryPageState extends State<CategoryPage>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;

  @override
  void initState() {
    _controller = AnimationController(vsync: this);
    super.initState();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 4,
      child: Scaffold(
        appBar: AppBar(
          automaticallyImplyLeading: false,
          backgroundColor: Colors.purple,
          title: Row(
            children: <Widget>[
              Expanded(
                child: TabBar(
                  tabs: <Widget>[
                    Tab(text: '章节'),
                    Tab(text: '答题'),
                    Tab(text: '视频'),
                    Tab(text: '笔记'),
                  ],
                ),
              )
            ],
          ),
        ),
        body: TabBarView(
          children: <Widget>[
            ListView(
              children: dati.map((value) {
                return Card(
                  elevation: 10.0,
                  margin: EdgeInsets.all(30),
                  child: Column(
                    children: <Widget>[
                      AspectRatio(
                        aspectRatio: 20 / 9,
                        child: Image.network(
                          value["imageUrl"],
                          fit: BoxFit.cover,
                        ),
                      ),
                      ListTile(
                        leading: CircleAvatar(
                            backgroundImage: NetworkImage(value["imageUrl"])),
                        title: Text(value["title"]),
                        subtitle: Text(value["description"],
                            maxLines: 1, overflow: TextOverflow.ellipsis),
                        onTap: () {
                          Navigator.of(context).push(MaterialPageRoute(
                              builder: (context) => ChapterOne()));
                        },
                      ),
                    ],
                  ),
                );
              }).toList(),
            ),
            ListView(
              children: <Widget>[
                Container(
                    width: MediaQuery.of(context).size.width,
                    height: 600.0,
                    child: Swiper(
                      itemBuilder: (BuildContext context, int index) {
                        //淡入淡出
                        return Column(
                          children: <Widget>[
                            Container(
                              margin: EdgeInsets.all(30),
                              height: 200,
                              child: Text(question[index]["ques"] +
                                  "\n\n\n" +
                                  question[index]["A"] +
                                  "\n\n\n" +
                                  question[index]["B"] +
                                  "\n\n\n" +
                                  question[index]["C"]),
                            ),
                            Container(
                                margin: EdgeInsets.all(20),
                                child: Row(
                                  children: <Widget>[
                                    RaisedButton(
                                      child: Text("A"),
                                      shape: CircleBorder(
                                          side: BorderSide(
                                        color: Colors.purple,
                                      )),
                                      onPressed: () {
                                        if (question[index]["answer"] == "A") {
                                          showDialog(
                                              context: context,
                                              builder: (context) => AlertDialog(
                                                    title: Text("回答正确"),
                                                    content: Text("正确答案:" +
                                                        question[index]
                                                            ["answer"]),
                                                    actions: <Widget>[
                                                      new FlatButton(
                                                        child: new Text("确定"),
                                                        onPressed: () {
                                                          Navigator.of(context)
                                                              .pop();
                                                        },
                                                      ),
                                                    ],
                                                  ));
                                        } else {
                                          showDialog(
                                              context: context,
                                              builder: (context) => AlertDialog(
                                                    title: Text("回答错误"),
                                                    content: Text("正确答案:" +
                                                        question[index]
                                                            ["answer"]),
                                                    actions: <Widget>[
                                                      new FlatButton(
                                                        child: new Text("确定"),
                                                        onPressed: () {
                                                          Navigator.of(context)
                                                              .pop();
                                                        },
                                                      ),
                                                    ],
                                                  ));
                                        }
                                      },
                                    ),
                                    RaisedButton(
                                      child: Text("B"),
                                      shape: CircleBorder(
                                          side:
                                              BorderSide(color: Colors.purple)),
                                      onPressed: () {
                                        if (question[index]["answer"] == "B") {
                                          showDialog(
                                              context: context,
                                              builder: (context) => AlertDialog(
                                                    content: Text("正确答案:" +
                                                        question[index]
                                                            ["answer"]),
                                                    title: Text("回答正确"),
                                                    actions: <Widget>[
                                                      new FlatButton(
                                                        child: new Text("确定"),
                                                        onPressed: () {
                                                          Navigator.of(context)
                                                              .pop();
                                                        },
                                                      ),
                                                    ],
                                                  ));
                                        } else {
                                          showDialog(
                                              context: context,
                                              builder: (context) => AlertDialog(
                                                    title: Text("回答错误"),
                                                    content: Text("正确答案:" +
                                                        question[index]
                                                            ["answer"]),
                                                    actions: <Widget>[
                                                      new FlatButton(
                                                        child: new Text("确定"),
                                                        onPressed: () {
                                                          Navigator.of(context)
                                                              .pop();
                                                        },
                                                      ),
                                                    ],
                                                  ));
                                        }
                                      },
                                    ),
                                    RaisedButton(
                                      child: Text("C"),
                                      shape: CircleBorder(
                                          side:
                                              BorderSide(color: Colors.purple)),
                                      onPressed: () {
                                        if (question[index]["answer"] == "C") {
                                          showDialog(
                                              context: context,
                                              builder: (context) => AlertDialog(
                                                    content: Text("正确答案:" +
                                                        question[index]
                                                            ["answer"]),
                                                    title: Text("回答正确"),
                                                    actions: <Widget>[
                                                      new FlatButton(
                                                        child: new Text("确定"),
                                                        onPressed: () {
                                                          Navigator.of(context)
                                                              .pop();
                                                        },
                                                      ),
                                                    ],
                                                  ));
                                        } else {
                                          showDialog(
                                              context: context,
                                              builder: (context) => AlertDialog(
                                                    title: Text("回答错误"),
                                                    content: Text("正确答案:" +
                                                        question[index]
                                                            ["answer"]),
                                                    actions: <Widget>[
                                                      new FlatButton(
                                                        child: new Text("确定"),
                                                        onPressed: () {
                                                          Navigator.of(context)
                                                              .pop();
                                                        },
                                                      ),
                                                    ],
                                                  ));
                                        }
                                      },
                                    )
                                  ],
                                ))
                          ],
                        );
                      },
                      itemCount: question.length,
                      pagination: new SwiperPagination(),
                      scrollDirection: Axis.vertical,
                    )),
              ],
            ),
            ListView(
              children: <Widget>[
                Card(
                  color: Colors.purple,
                  elevation: 20.0,
                  margin: EdgeInsets.all(10.0),
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(10.0)),
                  semanticContainer: true,
                  child: Column(
                    children: <Widget>[
                      Container(
                        margin: EdgeInsets.only(top: 40),
                        height: MediaQuery.of(context).size.height / 1.8,
                        child: SimpleViewPlayer(
                          "http://47.102.146.16/mp4/vue1.mp4",
                          isFullScreen: false,
                        ),
                      ),
                      ButtonBar(
                        children: <Widget>[
                          FlatButton(
                            child: Text("vue3.0"),
                            onPressed: () {},
                          ),
                          FlatButton(
                            child: Text("尤雨溪"),
                            onPressed: () {},
                          ),
                        ],
                      )
                    ],
                  ),
                )
              ],
            ),
            ListView(
              children: listData.map((value) {
                return ;
                  /*Card(
                  margin: EdgeInsets.all(30),
                  child: Column(
                    children: <Widget>[
                      AspectRatio(
                        aspectRatio: 20 / 9,
                        child: Image.network(
                          value["imageUrl"],
                          fit: BoxFit.cover,
                        ),
                      ),
                      ListTile(
                        leading: CircleAvatar(
                            backgroundImage: NetworkImage(value["imageUrl"])),
                        title: Text(value["title"]),
                        subtitle: Text(value["description"],
                            maxLines: 1, overflow: TextOverflow.ellipsis),
                        onTap: () {},
                      )
                    ],
                  ),
                )*/

              }).toList(),
            )
          ],
        ),
      ),
    );
  }
}
